{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "066fab85",
   "metadata": {},
   "source": [
    "-----\n",
    "* 2022/9/19\n",
    "* python学习记录\n",
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31edf1dd",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1.控制流\n",
    ">> 1.条件判断  \n",
    ">> 2.循环遍历\n",
    "\n",
    "> 2.随机函数\n",
    "\n",
    "> 3.时间函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8d62dca",
   "metadata": {},
   "source": [
    "## 1.控制流\n",
    "\n",
    "### 1.1条件判断\n",
    "\n",
    "* 知识点\n",
    "> 1.赋值 是 “=”  \n",
    "> 2.判断是否两者相等 是 “=”  \n",
    "> 3.代码中出现的变量，必须先定义，否则：name 变量名 is not defined"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1ed06726",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'today' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mtoday\u001b[49m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSaturday\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m      2\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mParty!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m today \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSunday\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n",
      "\u001b[1;31mNameError\u001b[0m: name 'today' is not defined"
     ]
    }
   ],
   "source": [
    "if today == \"Saturday\":\n",
    "    print(\"Party!\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "         print(\"Recover, then rest.\")\n",
    "    else:         \n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "     print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "857910fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Party!\n"
     ]
    }
   ],
   "source": [
    "today = \"Saturday\"\n",
    "if today == \"Saturday\":\n",
    "     print(\"Party!\")\n",
    "elif today == \"Sunday\":\n",
    "    if condition == \"Headache\":\n",
    "         print(\"Recover, then rest.\")\n",
    "    else:\n",
    "         print(\"Rest.\")\n",
    "else:\n",
    "     print(\"Work, work, work.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e8368a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 关于if else条件判断实践：\n",
    "## 请判断今天是周几，如果是周一，有Python课，好开心呀。如果不是，好期待周一呀。（time可以帮我们知道今天周几）\n",
    "##                   如果是周一，请判断现在是否正在上Python课。（time可以帮我们知道现在是几点钟几分钟）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "890f5025",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e1bd9add",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=9, tm_mday=19, tm_hour=10, tm_min=27, tm_sec=0, tm_wday=0, tm_yday=262, tm_isdst=0)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7fc310de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime().tm_wday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "395155ba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "周几 0\n",
      "几点 10\n",
      "几分 33\n"
     ]
    }
   ],
   "source": [
    "# tm_wday 0-6 0是周一\n",
    "wday = time.localtime().tm_wday\n",
    "print(\"周几\",wday)\n",
    "today_hour = time.localtime().tm_hour\n",
    "print(\"几点\",today_hour)\n",
    "today_min = time.localtime().tm_min\n",
    "print(\"几分\",today_min)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "b20012c0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "9def2aeb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "有Python课，好开心呀\n",
      "正在上Python课\n"
     ]
    }
   ],
   "source": [
    "wday = time.localtime().tm_wday\n",
    "if wday == 0:\n",
    "    print(\"有Python课，好开心呀\")\n",
    "    if 9 < today_hour < 12:\n",
    "        print(\"正在上Python课\")\n",
    "    elif today_hour == 9:\n",
    "            if today_min >= 45:\n",
    "                print(\"正在上Python课\") \n",
    "            else:\n",
    "                print(\"马上就要上Python课，芜湖~\")\n",
    "    else:\n",
    "        print(\"没在上Python课\")\n",
    "else:\n",
    "    print(\"期待周一呀\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "4a0c64e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "ff398b37",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "周几 0\n",
      "几点 11\n",
      "几分 19\n",
      "今天是周一，有Python课，好开心呀\n",
      "现在是 11 点 19 分 正在上Python课\n"
     ]
    }
   ],
   "source": [
    "wday = time.localtime().tm_wday\n",
    "print(\"周几\",wday)\n",
    "today_hour = time.localtime().tm_hour\n",
    "print(\"几点\",today_hour)\n",
    "today_min = time.localtime().tm_min\n",
    "print(\"几分\",today_min)\n",
    "wday = time.localtime().tm_wday\n",
    "if wday == 0:\n",
    "    print(\"今天是周一，有Python课，好开心呀\")\n",
    "    if 9 < today_hour < 12:\n",
    "        print(\"现在是\",today_hour,\"点\",today_min,\"分\",\"正在上Python课\")\n",
    "    elif today_hour == 9:\n",
    "            if today_min >= 45:\n",
    "                print(\"正在上Python课\") \n",
    "            elif today_min == 30:\n",
    "                print(\"手机弹出框：还有15分钟就要上Python课了，请提前准备好课本和电脑，检查好电量！\")\n",
    "            else:\n",
    "                print(\"马上就要上Python课，芜湖~\")\n",
    "    else:\n",
    "        print(\"没在上Python课\")\n",
    "else:\n",
    "    print(\"期待周一呀\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e1f1a3c",
   "metadata": {},
   "source": [
    "## 2.循环遍历（for）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "85b7b7f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in [1,2,3]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "46520c4e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "for ch in \"Hi!\":\n",
    "    print(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b36915f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 上述 i 和 ch 都是变量，可以根据我们的需求定义变量名\n",
    "# 每一次执行就赋值一次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "444ec57c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "芜湖！\n",
      "芜湖！\n",
      "芜湖！\n",
      "芜湖！\n",
      "芜湖！\n",
      "芜湖！\n",
      "芜湖！\n",
      "芜湖！\n",
      "芜湖！\n",
      "芜湖！\n"
     ]
    }
   ],
   "source": [
    "# range(): 范围，区间\n",
    "for num in range(10):\n",
    "    print(\"芜湖！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "84d39169",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# range()是一个数字/数值生成器，每次增加1\n",
    "# range() 包含有 起始点start（默认为0） 终止点 stop 以及步长step（默认为1）\n",
    "range(5) # 默认的起点是 0 ，终结点是 5  产生了5-0个数值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "02adf1ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5,10))# 自定义的起点是 5 ，终结点是 10 产生了10-5个数值，每次增加1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "30a7eb6a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 10, 3)"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(0,10,3)# 自定义的起点是 0 ，终结点是 10 自定义每次增加3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "4067ab41",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 3, 6, 9]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0,10,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "e8163ce9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/tzgg/index0.htm\n",
      "https://www.nfu.edu.cn/tzgg/index1.htm\n",
      "https://www.nfu.edu.cn/tzgg/index2.htm\n",
      "https://www.nfu.edu.cn/tzgg/index3.htm\n",
      "https://www.nfu.edu.cn/tzgg/index4.htm\n",
      "https://www.nfu.edu.cn/tzgg/index5.htm\n",
      "https://www.nfu.edu.cn/tzgg/index6.htm\n",
      "https://www.nfu.edu.cn/tzgg/index7.htm\n",
      "https://www.nfu.edu.cn/tzgg/index8.htm\n",
      "https://www.nfu.edu.cn/tzgg/index9.htm\n",
      "https://www.nfu.edu.cn/tzgg/index10.htm\n",
      "https://www.nfu.edu.cn/tzgg/index11.htm\n",
      "https://www.nfu.edu.cn/tzgg/index12.htm\n",
      "https://www.nfu.edu.cn/tzgg/index13.htm\n",
      "https://www.nfu.edu.cn/tzgg/index14.htm\n",
      "https://www.nfu.edu.cn/tzgg/index15.htm\n",
      "https://www.nfu.edu.cn/tzgg/index16.htm\n",
      "https://www.nfu.edu.cn/tzgg/index17.htm\n",
      "https://www.nfu.edu.cn/tzgg/index18.htm\n",
      "https://www.nfu.edu.cn/tzgg/index19.htm\n",
      "https://www.nfu.edu.cn/tzgg/index20.htm\n",
      "https://www.nfu.edu.cn/tzgg/index21.htm\n",
      "https://www.nfu.edu.cn/tzgg/index22.htm\n",
      "https://www.nfu.edu.cn/tzgg/index23.htm\n",
      "https://www.nfu.edu.cn/tzgg/index24.htm\n",
      "https://www.nfu.edu.cn/tzgg/index25.htm\n",
      "https://www.nfu.edu.cn/tzgg/index26.htm\n",
      "https://www.nfu.edu.cn/tzgg/index27.htm\n",
      "https://www.nfu.edu.cn/tzgg/index28.htm\n",
      "https://www.nfu.edu.cn/tzgg/index29.htm\n",
      "https://www.nfu.edu.cn/tzgg/index30.htm\n",
      "https://www.nfu.edu.cn/tzgg/index31.htm\n",
      "https://www.nfu.edu.cn/tzgg/index32.htm\n",
      "https://www.nfu.edu.cn/tzgg/index33.htm\n",
      "https://www.nfu.edu.cn/tzgg/index34.htm\n",
      "https://www.nfu.edu.cn/tzgg/index35.htm\n",
      "https://www.nfu.edu.cn/tzgg/index36.htm\n"
     ]
    }
   ],
   "source": [
    "# 实践: 数据挖掘-获取页面URL队列\n",
    "学校要闻 = \"xxyw\"\n",
    "学校要闻_page = 110\n",
    "\n",
    "通知公告 = \"tzgg\"\n",
    "\n",
    "for page in range(37):\n",
    "    print(\"https://www.nfu.edu.cn/tzgg/index\" + str(page) +\".htm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6dcb1bed",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d6b8adf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36880773",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
